Skip to content

Add server stream events #2068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Sep 23, 2024

Motivation:

As a service author it's useful to know if the underlying stream has been cancelled (because it's timed out, the remote peer closed it, the connection dropped etc).

For cases where the stream has already closed this can be surfaced by a read or write failing. However, for cases like server-streaming RPCs where there are no reads and writes can be infrequent it's useful to have a more explicit signal.

Modifications:

  • Add a ServerStreamState which provides two API for this:
    • An explicit "has this RPC been cancelled?"
    • An async sequence of events which can happen the underlying stream
  • Add the stream state to the server context
  • Update the in-process transport to use this

Result:

Server context includes a way for users to know if their RPC has been cancelled.

Motivation:

As a service author it's useful to know if the underlying stream has
been cancelled (because it's timed out, the remote peer closed it, the
connection dropped etc).

For cases where the stream has already closed this can be surfaced by a
read or write failing. However, for cases like server-streaming RPCs
where there are no reads and writes can be infrequent it's useful to
have a more explicit signal.

Modifications:

- Add a `ServerStreamState` which provides two API for this:
  - An explicit "has this RPC been cancelled?"
  - An async sequence of events which can happen the underlying stream
- Add the stream state to the server context
- Update the in-process transport to use this

Result:

Server context includes a way for users to know if their RPC has been
cancelled.
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Sep 23, 2024
@glbrntt glbrntt requested a review from gjcairo September 23, 2024 14:49
import Synchronization

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public struct ServerStreamState: Sendable {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For discussion: I don't like this name.

The other idea I had was ServerStreamContext which is potentially better and aligns with ServerContext. Downside is that it hints at a slightly wide use.

Another option: rather than nesting Events have a ServerStreamEvents type which also has a computed property for isRPCCancelled (i.e. an AsyncSequence with extra API).

@glbrntt glbrntt marked this pull request as ready for review September 23, 2024 15:25
@glbrntt
Copy link
Collaborator Author

glbrntt commented Oct 8, 2024

Closing in favour of #2090

@glbrntt glbrntt closed this Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant